package com.example.dqhl.recycleviewdemo.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;

import com.example.dqhl.recycleviewdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TimeActivity extends AppCompatActivity {

    @BindView(R.id.datapicker)
    DatePicker datapicker;
    @BindView(R.id.timepicker)
    TimePicker timepicker;
    @BindView(R.id.buttone1)
    Button buttone1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time);
        ButterKnife.bind(this);
        //是否使用24小时制
        timepicker.setIs24HourView(true);
        TimeListener times = new TimeListener();
        timepicker.setOnTimeChangedListener(times);

    }

    @OnClick(R.id.buttone1)
    public void onViewClicked() {
        int h = timepicker.getCurrentHour();
        int m = timepicker.getCurrentMinute();
        System.out.println("h:" + h + "   m:" + m);
    }

    class TimeListener implements OnTimeChangedListener {

        /**
         * view 当前选中TimePicker控件
         * hourOfDay 当前控件选中TimePicker 的小时
         * minute 当前选中控件TimePicker  的分钟
         */
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            // TODO Auto-generated method stub
            System.out.println("h:" + hourOfDay + " m:" + minute);
        }

    }

}
